<?php
namespace App\Admin\Controllers;

use App\Admin\Model\User;

class HomeController extends BackendController {

	public function actionIndex() {
        $data = post();
        if (request()->ajax && !empty($data)) {
            return response()->redirect('/');
        }

        $this->htmlTitle = 'Admin - Signin Template · Bootstrap';
        $html = $this->render('user/login');
        return response($html)->send();
	}

    public function actionTestdb() {
//        $db = $this->app['db'];
//        $db->open();
//        $res = $db->createCommand('SELECT * FROM {{%user}}')->queryAll();
//        echo '<pre>';
//        print_r($res);
//
//        $command = $db->createCommand();
//        $res = $command->setSql('SELECT * FROM {{%user}}')->queryAll();
//        print_r($res);
//
//        $res = (new Query)
//            ->select('*')
//            ->from('{{%user}}')
//            ->where(['account' => 'kerry'])
//            ->one();
//        print_r($res);

//        $subQuery = (new Query())->select('COUNT(*)')->from('{{%user}}');
//
//        // SELECT `id`, (SELECT COUNT(*) FROM `user`) AS `count` FROM `post`
//        $query = (new Query())->select(['uid', 'count' => $subQuery])->from('{{%user}}');
//
//        p($query->all());

//        $command = $user::find()->createCommand();
//        echo '<pre>';
//        $res = $command->setSql('SELECT * FROM {{%user}}')->queryAll();
//        print_r($res);
//        $res = $user::findOne(['uid' => 10001]);
//        print_r($res);
        $res = User::find()->select('COUNT(*)')->from('{{%user}}')->scalar();
        p($res);
    }
}
